﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ANZ_AIM_GUI.Utils;
using ANZ_AIM_BLL;
using ANZ_AIM_FRAMEWORK;
using ANZ_AIM_BLL.Model;
using DevComponents.DotNetBar.Controls;
using log4net;

namespace ANZ_AIM_OFFLINETOOL
{
    public partial class frmCandidateOffline : Form
    {
        //log4net
        private static readonly ILog logger = LogManager.GetLogger(typeof(frmCandidateOffline));

        public int OpMode { get; set; }
        public CandidateOffline candidateOffline { get; set; }
        private List<CandidateOffline> listCandidateOffline = new List<CandidateOffline>();

        public List<CandidateOffline> ListCandidateOffline
        {
            get { return listCandidateOffline; }
            set { listCandidateOffline = value; }
        }

        public frmCandidateOffline()
        {
            InitializeComponent();
        }



        public frmCandidateOffline(int mode, List<CandidateOffline> listCandidateOffline)
            : this()
        {
            try
            {
                this.OpMode = mode;
                this.listCandidateOffline = listCandidateOffline;

                InitData();
                switch (OpMode)
                {
                    case MiscHelper.FORM_OPMODE_ADD_NEW:
                        this.Text = "ADD CANDIDATE OFFLINE";
                        break;
                    case MiscHelper.FORM_OPMODE_EDIT:
                        this.Text = "EDIT CANDIDATE OFFLINE";
                        btnAdd.Text = "UPDATE";

                        //unpack object
                        candidateOffline = listCandidateOffline[0];
                        UnPackObjectData_Candidate();
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #region InitData

        private void InitData()
        {
            LoadCity(txtCity);
            LoadStatus(cbTrainingCallStatus);
            LoadStatus(cbTrainingAttendance);
            LoadStatus(cbPECCheckResult);
            LoadStatus(cbDocumentCompletion);
            LoadStatus(cbOBEligible);
            LoadStatus(cbOnBoarding);
            LoadSanctionResult();
            LoadCICResult();
            LoadRetest();
            LoadTrainingResulCC();
            LoadChannel(cbChannel);
            LoadTeam();
        }

        private void LoadChannel(ComboBox cbData)
        {
            MasterDataBLL masterDataBll = new MasterDataBLL();
            DataTable dtResult = masterDataBll.GetById(MasterData.CHANNEL);

            cbData.DataSource = dtResult;
            cbData.ValueMember = MasterData.KEY;
            cbData.DisplayMember = MasterData.VALUE;
            cbData.SelectedIndex = 0;
        }



        private void LoadTeam()
        {
            List<string> teamList = new List<string>();
            new MasterDataBLL().GetById(MasterData.TEAMNAME).Rows.OfType<DataRow>().ToList<DataRow>().ForEach(r => teamList.Add(r["KeyValue"].ToString()));
            string[] teamArray = teamList.ToArray<string>();
            cbbTeam.DataSource = teamArray;
            //txtTeam.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            //txtTeam.AutoCompleteSource = AutoCompleteSource.CustomSource;
            //var source = new AutoCompleteStringCollection();
            //source.AddRange(teamArray);
            //txtTeam.AutoCompleteCustomSource = source;
        }

        private void LoadCity(TextBoxX txtCity)
        {
            List<string> cityList = new List<string>();
            new MasterDataBLL().GetById(MasterData.CITY).Rows.OfType<DataRow>().ToList<DataRow>().ForEach(r => cityList.Add(r["KeyValue"].ToString()));
            string[] teamArray = cityList.ToArray<string>();
            txtCity.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            txtCity.AutoCompleteSource = AutoCompleteSource.CustomSource;
            var source = new AutoCompleteStringCollection();
            source.AddRange(teamArray);
            txtCity.AutoCompleteCustomSource = source;
        }

        private void LoadStatus(ComboBox cbData)
        {
            cbData.Items.AddRange(new string[] { "1.Yes",
                                                    "2.No"
                                                   });
            cbData.SelectedIndex = 0;
        }



        private void LoadSanctionResult()
        {
            cbSanctionResult.Items.AddRange(new string[] { "Positive"
                                                   });
            cbSanctionResult.SelectedIndex = 0;
        }
        private void LoadCICResult()
        {
            cbCICResult.Items.AddRange(new string[] { "No Loan"
                                                   });
            cbCICResult.SelectedIndex = 0;
        }
        private void LoadRetest()
        {
            MasterDataBLL masterDataBll = new MasterDataBLL();
            DataTable dtResult = masterDataBll.GetById(MasterData.RETEST);

            cbReTest.DataSource = dtResult;
            cbReTest.ValueMember = MasterData.KEY;
            cbReTest.DisplayMember = MasterData.VALUE;

            cbReTest.SelectedIndex = 0;
        }
        private void LoadTrainingResulCC()
        {
            cbTrainingResultCC.Items.AddRange(new string[] { "Pass" });
            cbTrainingResultCC.SelectedIndex = 0;
        }

        #endregion

        #region Action

        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (!this.validateForm())
                    return;

                this.PackObjectData_CandidateOffline();
                switch (OpMode)
                {
                    case MiscHelper.FORM_OPMODE_ADD_NEW:
                        bool duplicate = false;
                        foreach (CandidateOffline candidate in listCandidateOffline)
                        {
                            if (!(candidateOffline.CVCode == candidate.CVCode))
                            {
                                duplicate = true;
                            }
                        }
                        if (!duplicate)
                        {

                            //listCandidateOffline
                            listCandidateOffline.Add(candidateOffline);
                            MessageBox.Show("New Candidate added.", Constant.SYS_INFORMATION, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            clearForm();
                        }
                        else
                        {
                            MessageBox.Show("Duplicate CV Code!", Constant.SYS_INFORMATION, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            txtPersonalCode.Focus();
                        }
                        //this.DialogResult = DialogResult.OK;
                        break;
                    case MiscHelper.FORM_OPMODE_EDIT:
                        MessageBox.Show("Candidate saved.", Constant.SYS_INFORMATION, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                        break;
                    default:
                        break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.InnerException == null ? ex.Message : ex.InnerException.Message, Constant.SYS_ERROR, MessageBoxButtons.OK);
                logger.Error(ex.Message + " - " + ex.StackTrace);
            }
        }
        private void btnClear_Click(object sender, EventArgs e)
        {
            if (btnAdd.Text.Equals("ADD"))
            {
                clearForm();
            }
            else
            {
                UnPackObjectData_Candidate();
            }
        }
        public void clearForm()
        {
            //group personalinfo
            txtPersonalCode.Text = "";
            cbChannel.SelectedIndex = 0;
            cbbTeam.SelectedIndex = -1;
            txtFullNameE.Text = "";
            txtFullNameV.Text = "";
            txtCellPhone.Text = "";
            dtDOB.IsEmpty = true;
            txtCollege.Text = "";
            txtQualification.Text = "";
            txtInterviewer.Text = "";
            txtIDNumber.Text = "";
            dtIssuedDate.IsEmpty = true;
            txtCity.Text = "";
            txtPermanentAddress.Text = "";
            dtInterviewDate.IsEmpty = true;
            cbTrainingCallStatus.SelectedIndex = 0;
            txtTraningCallStatusRemark.Text = "";

            //group pre-employeecheck
            dtCICSactionDeliveryDate.IsEmpty = true;
            txtCICSanctionDN.Text = "";
            cbCICResult.SelectedIndex = 0;
            cbSanctionResult.SelectedIndex = 0;
            cbPECCheckResult.SelectedIndex = 0;
            txtPECRemark.Text = "";

            //group on-boarding training
            txtTrainingBatch.Text = "";
            dtTrainingDate.IsEmpty = true;
            txtTrainerName.Text = "";
            cbTrainingAttendance.SelectedIndex = 0;
            txtTraingingAttendanceRemark.Text = "";
            cbReTest.SelectedIndex = 0;
            txtRetestRequirement.Text = "";
            txtTrainingResult.Text = "";

            //group on-boarding documentation
            cbOBEligible.SelectedIndex = 0;
            cbDocumentCompletion.SelectedIndex = 0;
            txtDocumentIncompletionRemark.Text = "";
            dtPCReceipt.IsEmpty = true;
            dtPCReport.IsEmpty = true;

            //group onboarding-approval
            txtHiringManager.Text = "";
            dtHMAckDate.IsEmpty = true;
            txtDelegateApproveName.Text = "";
            dtApprovingDate.IsEmpty = true;
            cbOnBoarding.SelectedIndex = 0;
            dtOnboardingRemark.IsEmpty = true;
            dtCICSanctionRequest.IsEmpty = true;
            cbTrainingResultCC.SelectedIndex = 0;
            txtCheckChannel.Text = "";
        }
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void txtCellPhone_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = (!char.IsDigit(e.KeyChar)) && (!char.IsControl(e.KeyChar));
        }
        private void txtIDNumber_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = (!char.IsDigit(e.KeyChar)) && (!char.IsControl(e.KeyChar));
        }
        private void txtCellPhone_TextChanged(object sender, EventArgs e)
        {
            if (System.Text.RegularExpressions.Regex.IsMatch(txtCellPhone.Text, "[^0-9]"))
            {
                txtCellPhone.Text = "";
            }
        }
        private void txtIDNumber_TextChanged(object sender, EventArgs e)
        {
            if (System.Text.RegularExpressions.Regex.IsMatch(txtIDNumber.Text, "[^0-9]"))
            {
                txtIDNumber.Text = "";
            }
        }

        #endregion

        private bool validateForm()
        {
            try
            {
                if (string.IsNullOrEmpty(txtPersonalCode.Text.Trim()))
                {
                    MessageBox.Show("CV Code cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtPersonalCode.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(cbbTeam.SelectedValue.ToString().Trim()))
                {
                    MessageBox.Show("Team cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    cbbTeam.Focus();
                    return false;
                }
                else if (cbbTeam.SelectedValue.ToString().Trim().Length < 6)
                {
                    MessageBox.Show("Wrong Team name.\n Please check agian!", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    cbbTeam.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(txtFullNameE.Text.Trim()))
                {
                    MessageBox.Show("Full Name E cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtFullNameE.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(txtFullNameV.Text.Trim()))
                {
                    MessageBox.Show("Full Name V cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtFullNameV.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(txtCellPhone.Text.Trim()))
                {
                    MessageBox.Show("Cell Phone cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtCellPhone.Focus();
                    return false;
                }
                else if (dtDOB.IsEmpty)
                {
                    MessageBox.Show("Date Of Birth cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    dtDOB.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(txtCollege.Text.Trim()))
                {
                    MessageBox.Show("College cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtCollege.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(txtQualification.Text.Trim()))
                {
                    MessageBox.Show("Qualification cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtQualification.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(txtInterviewer.Text.Trim()))
                {
                    MessageBox.Show("Interviewer cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtInterviewer.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(txtIDNumber.Text.Trim()))
                {
                    MessageBox.Show("ID Number cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtIDNumber.Focus();
                    return false;
                }
                else if (dtIssuedDate.IsEmpty)
                {
                    MessageBox.Show("Issued Date cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    dtIssuedDate.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(txtCity.Text.Trim()))
                {
                    MessageBox.Show("Issued Place cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtCity.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(txtPermanentAddress.Text.Trim()))
                {
                    MessageBox.Show("Permanent Address cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtPermanentAddress.Focus();
                    return false;
                }
                else if (dtInterviewDate.IsEmpty)
                {
                    MessageBox.Show("Interview Date cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    dtInterviewDate.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(txtTraningCallStatusRemark.Text.Trim()))
                {
                    MessageBox.Show("Traning Call Status Remark cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtTraningCallStatusRemark.Focus();
                    return false;
                }
                else if (dtCICSactionDeliveryDate.IsEmpty)
                {
                    MessageBox.Show("CIC Saction Delivery Date cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    dtCICSactionDeliveryDate.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(txtCICSanctionDN.Text.Trim()))
                {
                    MessageBox.Show("CIC Sanaction Deliverer Name cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtCICSanctionDN.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(txtPECRemark.Text.Trim()))
                {
                    MessageBox.Show("PEC Remark cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtPECRemark.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(txtTrainingBatch.Text.Trim()))
                {
                    MessageBox.Show("Training Batch cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtTrainingBatch.Focus();
                    return false;
                }
                else if (dtTrainingDate.IsEmpty)
                {
                    MessageBox.Show("Training Date cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    dtTrainingDate.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(txtTrainerName.Text.Trim()))
                {
                    MessageBox.Show("Trainer Name cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtTrainerName.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(txtTraingingAttendanceRemark.Text.Trim()))
                {
                    MessageBox.Show("Training Attendance Remark cannot be empty", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtTraingingAttendanceRemark.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(txtRetestRequirement.Text.Trim()))
                {
                    MessageBox.Show("Re-test Requirement cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtRetestRequirement.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(txtTrainingResult.Text.Trim()))
                {
                    MessageBox.Show("Training Result cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtTrainingResult.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(txtDocumentIncompletionRemark.Text.Trim()))
                {
                    MessageBox.Show("Document Incompletion Remarks cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtDocumentIncompletionRemark.Focus();
                    return false;
                }
                else if (dtPCReceipt.IsEmpty)
                {
                    MessageBox.Show("PC Receipt Submission Date cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    dtPCReceipt.Focus();
                    return false;
                }
                else if (dtPCReport.IsEmpty)
                {
                    MessageBox.Show("PC Report Submission Date: cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    dtPCReport.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(txtHiringManager.Text.Trim()))
                {
                    MessageBox.Show("Hiring Manager's Name cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtHiringManager.Focus();
                    return false;
                }
                else if (dtHMAckDate.IsEmpty)
                {
                    MessageBox.Show("Hiring Manager Acknowledge Date cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    dtHMAckDate.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(txtDelegateApproveName.Text.Trim()))
                {
                    MessageBox.Show("Delegate Approver's Name:  cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtDelegateApproveName.Focus();
                    return false;
                }
                else if (dtCICSanctionRequest.IsEmpty)
                {
                    MessageBox.Show("CIC-Sanction Request Date cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    dtCICSanctionRequest.Focus();
                    return false;
                }
                else if (dtOnboardingRemark.IsEmpty)
                {
                    MessageBox.Show("On-boarding Remarks Date cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    dtOnboardingRemark.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(txtCheckChannel.Text.Trim()))
                {
                    MessageBox.Show("Check Channel cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtCheckChannel.Focus();
                    return false;
                }
                else if (dtApprovingDate.IsEmpty)
                {
                    MessageBox.Show("Approving Date cannot be empty.", Constant.SYS_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    dtApprovingDate.Focus();
                    return false;
                }
                else
                {
                    return true;
                }
            }
            catch (Exception ex) { throw ex; }

        }
        private void UnPackObjectData_Candidate()
        {
            txtPersonalCode.Text = candidateOffline.CVCode;
            cbChannel.Text = candidateOffline.Channel;
            cbbTeam.Text = candidateOffline.Team;
            txtFullNameE.Text = candidateOffline.FullName_E;
            txtFullNameV.Text = candidateOffline.FullName_V;
            txtCellPhone.Text = candidateOffline.CellPhone;
            dtDOB.Value = Convert.ToDateTime(candidateOffline.DateOfBirth != null ? candidateOffline.DateOfBirth : (DateTime?)null);
            txtQualification.Text = candidateOffline.Qualification;
            txtCollege.Text = candidateOffline.College;
            txtIDNumber.Text = candidateOffline.IDNumber;
            dtIssuedDate.Value = Convert.ToDateTime(candidateOffline.IssuedDate != null ? candidateOffline.IssuedDate : (DateTime?)null);
            txtCity.Text = candidateOffline.IssuedPlace;
            txtPermanentAddress.Text = candidateOffline.PermanentAddress;
            txtInterviewer.Text = candidateOffline.Interviewer;
            dtInterviewDate.Value = Convert.ToDateTime(candidateOffline.InterviewDate != null ? candidateOffline.InterviewDate : (DateTime?)null);
            cbTrainingCallStatus.Text = candidateOffline.TrainingCallStatus;
            txtTraningCallStatusRemark.Text = candidateOffline.TrainingCallStatusRemarks;

            dtCICSactionDeliveryDate.Value = Convert.ToDateTime(candidateOffline.CICSanctionDeliveryDate != null ? candidateOffline.CICSanctionDeliveryDate : (DateTime?)null);
            txtCICSanctionDN.Text = candidateOffline.CICSanctionDelivererName;
            cbCICResult.Text = candidateOffline.CICResult;
            cbSanctionResult.Text = candidateOffline.SanctionResult;
            cbPECCheckResult.Text = candidateOffline.PECCheckResult;
            txtPECRemark.Text = candidateOffline.PECRemarks;

            txtTrainingBatch.Text = candidateOffline.TrainingBatch;
            dtTrainingDate.Value = Convert.ToDateTime(candidateOffline.TrainingDate != null ? candidateOffline.TrainingDate : (DateTime?)null);
            txtTrainerName.Text = candidateOffline.TrainerName;
            cbTrainingAttendance.Text = candidateOffline.TrainingAttendance;
            txtTraingingAttendanceRemark.Text = candidateOffline.TrainingAttendanceRemarks;
            cbReTest.Text = candidateOffline.ReTest;
            txtRetestRequirement.Text = candidateOffline.ReTestRequirement;
            txtTrainingResult.Text = candidateOffline.TrainingResult;

            cbOBEligible.Text = candidateOffline.OBEligible;
            cbDocumentCompletion.Text = candidateOffline.DocumentCompletion;
            txtDocumentIncompletionRemark.Text = candidateOffline.DocumentIncompletionRemarks;
            dtPCReceipt.Value = Convert.ToDateTime(candidateOffline.PCReceiptSubmissionDate != null ? candidateOffline.PCReceiptSubmissionDate : (DateTime?)null);
            dtPCReport.Value = Convert.ToDateTime(candidateOffline.PCReportSubmissionDate != null ? candidateOffline.PCReportSubmissionDate : (DateTime?)null);

            txtHiringManager.Text = candidateOffline.HiringManagerName;
            dtHMAckDate.Value = Convert.ToDateTime(candidateOffline.HiringManagerAcknowledgeDate != null ? candidateOffline.HiringManagerAcknowledgeDate : (DateTime?)null);
            txtDelegateApproveName.Text = candidateOffline.DelegateApproverName;
            dtApprovingDate.Value = Convert.ToDateTime(candidateOffline.ApprovingDate != null ? candidateOffline.ApprovingDate : (DateTime?)null);
            cbOnBoarding.Text = candidateOffline.OnBoarding;
            dtOnboardingRemark.Value = Convert.ToDateTime(candidateOffline.OnBoardingRemarks != null ? candidateOffline.OnBoardingRemarks : (DateTime?)null);
            dtCICSanctionRequest.Value = Convert.ToDateTime(candidateOffline.CICSanctionRequestDate != null ? candidateOffline.CICSanctionRequestDate : (DateTime?)null);
            cbTrainingResultCC.Text = candidateOffline.TrainingResultCC;
            txtCheckChannel.Text = candidateOffline.CheckChannel;
        }
        private void PackObjectData_CandidateOffline()
        {
            candidateOffline = new CandidateOffline();
            candidateOffline.CVCode = txtPersonalCode.Text.Trim();
            candidateOffline.Channel = cbChannel.Text;
            string selectedItem = cbChannel.Text;
            string[] noTeam_Channel = new string[] {
                "TS In-house HN 1", "TS In-house HN 2", "TS In-house HN 3",
                "TS In-house 1", "TS In-house 2", "TS In-house 3",
                "TS In-house 4", "TS Portfolio", "Field Sales HN", "Field Sales HCM"
            };
            if (noTeam_Channel.ToList<string>().Any(i => i.Equals(selectedItem)))
            {
                candidateOffline.Team = "";
            }
            else
            {
                candidateOffline.Team = cbbTeam.SelectedValue.ToString().Trim();
            }

            candidateOffline.FullName_E = txtFullNameE.Text.Trim();
            candidateOffline.FullName_V = txtFullNameV.Text.Trim();
            candidateOffline.CellPhone = txtCellPhone.Text.Trim();
            candidateOffline.DateOfBirth = MiscHelper.DateTimeToShort(dtDOB.Value);
            candidateOffline.Qualification = txtQualification.Text;
            candidateOffline.College = txtCollege.Text;
            candidateOffline.IDNumber = txtIDNumber.Text.Trim();
            candidateOffline.IssuedDate = MiscHelper.DateTimeToShort(dtIssuedDate.Value);
            candidateOffline.IssuedPlace = txtCity.Text;
            candidateOffline.PermanentAddress = txtPermanentAddress.Text.Trim();
            candidateOffline.Interviewer = txtInterviewer.Text.Trim();
            candidateOffline.InterviewDate = MiscHelper.DateTimeToShort(dtInterviewDate.Value);
            candidateOffline.TrainingCallStatus = cbTrainingCallStatus.Text;
            candidateOffline.TrainingCallStatusRemarks = txtTraningCallStatusRemark.Text.Trim();

            candidateOffline.CICSanctionDeliveryDate = MiscHelper.DateTimeToShort(dtCICSactionDeliveryDate.Value);
            candidateOffline.CICSanctionDelivererName = txtCICSanctionDN.Text.Trim();
            candidateOffline.CICResult = cbCICResult.Text;
            candidateOffline.SanctionResult = cbSanctionResult.Text;
            candidateOffline.PECCheckResult = cbPECCheckResult.Text;
            candidateOffline.PECRemarks = txtPECRemark.Text.Trim();

            candidateOffline.TrainingBatch = txtTrainingBatch.Text.Trim();
            candidateOffline.TrainingDate = MiscHelper.DateTimeToShort(dtTrainingDate.Value);
            candidateOffline.TrainerName = txtTrainerName.Text.Trim();
            candidateOffline.TrainingAttendance = cbTrainingAttendance.Text;
            candidateOffline.TrainingAttendanceRemarks = txtTraingingAttendanceRemark.Text;
            candidateOffline.ReTest = cbReTest.Text;
            candidateOffline.ReTestRequirement = txtRetestRequirement.Text.Trim();
            candidateOffline.TrainingResult = txtTrainingResult.Text.Trim();

            candidateOffline.OBEligible = cbOBEligible.Text;
            candidateOffline.DocumentCompletion = cbDocumentCompletion.Text;
            candidateOffline.DocumentIncompletionRemarks = txtDocumentIncompletionRemark.Text;
            candidateOffline.PCReceiptSubmissionDate = MiscHelper.DateTimeToShort(dtPCReceipt.Value);
            candidateOffline.PCReportSubmissionDate = MiscHelper.DateTimeToShort(dtPCReport.Value);

            candidateOffline.HiringManagerName = txtHiringManager.Text;
            candidateOffline.HiringManagerAcknowledgeDate = MiscHelper.DateTimeToShort(dtHMAckDate.Value);
            candidateOffline.DelegateApproverName = txtDelegateApproveName.Text.Trim();
            candidateOffline.ApprovingDate = MiscHelper.DateTimeToShort(dtApprovingDate.Value);
            candidateOffline.OnBoarding = cbOnBoarding.Text;
            candidateOffline.OnBoardingRemarks = MiscHelper.DateTimeToShort(dtOnboardingRemark.Value);
            candidateOffline.CICSanctionRequestDate = MiscHelper.DateTimeToShort(dtCICSanctionRequest.Value);
            candidateOffline.TrainingResultCC = cbTrainingResultCC.Text;
            candidateOffline.CheckChannel = txtCheckChannel.Text;
        }

        private void cbChannel_SelectedIndexChanged(object sender, EventArgs e)
        {
            string selectedItem = cbChannel.Text;
            string[] noTeam_Channel = new string[] {
                "TS In-house HN 1", "TS In-house HN 2", "TS In-house HN 3",
                "TS In-house 1", "TS In-house 2", "TS In-house 3",
                "TS In-house 4", "TS Portfolio", "Field Sales HN", "Field Sales HCM"
            };
            if (noTeam_Channel.ToList<string>().Any(i => i.Equals(selectedItem)))
            {
                cbbTeam.Enabled = false;
            }
            else
            {
                cbbTeam.Enabled = true;
            }

        }

        private void txtCity_Click(object sender, EventArgs e)
        {
            List<string> getList = new List<string>();
            new MasterDataBLL().GetById(MasterData.CITY).Rows.OfType<DataRow>().ToList<DataRow>().ForEach(r => getList.Add(r["KeyValue"].ToString()));
            string[] array = getList.ToArray<string>();
            txtCity.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
            txtCity.AutoCompleteSource = AutoCompleteSource.CustomSource;
            var sourceCollection = new AutoCompleteStringCollection();
            sourceCollection.AddRange(array);
            txtCity.AutoCompleteCustomSource = sourceCollection;
        }

        //private void txtTeam_Click(object sender, EventArgs e)
        //{
        //    List<string> getList = new List<string>();
        //    new MasterDataBLL().GetById(MasterData.TEAMNAME).Rows.OfType<DataRow>().ToList<DataRow>().ForEach(r => getList.Add(r["KeyValue"].ToString()));
        //    string[] array = getList.ToArray<string>();
        //    txtTeam.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
        //    txtTeam.AutoCompleteSource = AutoCompleteSource.CustomSource;
        //    var sourceCollection = new AutoCompleteStringCollection();
        //    sourceCollection.AddRange(array);
        //    txtTeam.AutoCompleteCustomSource = sourceCollection;
        //}

        private void dtApprovingDate_Click(object sender, EventArgs e)
        {

        }

        private void groupBox2_Enter(object sender, EventArgs e)
        {

        }

        private void frmCandidateOffline_Load(object sender, EventArgs e)
        {

        }


    }
}
